
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;

public class RMISum extends UnicastRemoteObject implements IFSum
{    public RMISum() throws RemoteException {

    }

    public RMISum(String[] args) throws RemoteException {

    }

    public String sum(int v1, int v2) throws RemoteException {
        return String.valueOf( v1+v2 );
    }

    public void distributedEasyAcceptShutdown() throws RemoteException {
        org.dea.util.ExitTimer.exit(1000);

    }

    public boolean distributedEasyAcceptPing() throws RemoteException {
        return true;

    }

    public static void main(String[] args) throws RemoteException {
        if( args.length == 1 ){	Registry registry = LocateRegistry.createRegistry(Integer.parseInt(args[0]));
        	try{
        		IFSum facade = new RMISum();
        		registry.bind("IFSum", facade);
        	} catch (Exception ex){ ex.printStackTrace(); }
        } else if(args.length >1){
        	String[] newArgs = new String[args.length-1];
        	for(int i=1; i<args.length;i++){ newArgs[i-1] = args[i];}
        	Registry registry = LocateRegistry.createRegistry(Integer.parseInt(args[0]));
        	try{
        		IFSum facade = new RMISum(newArgs);
        		registry.bind("IFSum", facade);
        	} catch (Exception ex){ ex.printStackTrace(); }
        } else { throw new RuntimeException("Invalid number of parameters"+ args.length ); }
         
    }

} // end RMISum
